﻿using Service.Auth.Domain.AggregatesModel;
using Service.Core.Redis.Aop.Cache;
using Service.Core.Repository;
using Service.Framework;

namespace Service.Auth.Api.Application.Query;

/// <summary>
/// 客户端Api资源查询器
/// </summary>
/// <param name="clientScopesRepository"></param>
public class ClientScopesQueryService(IRepository<ClientScopes> clientScopesRepository) : IScopedService
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="clientId"></param>
    /// <returns></returns>
    [RedisCacheInterceptor($"{nameof(ClientScopesQueryService)}:{nameof(QueryClientScopesByClientId)}", cacheDuration: 60 * 30)]
    public async Task<List<ClientScopes>> QueryClientScopesByClientId(string clientId)
    {
        return (await QueryClientScopesList()).Where(s => s.ClientId.Equals(clientId)).ToList();
    }


    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [RedisCacheInterceptor($"{nameof(ClientScopesQueryService)}:{nameof(QueryClientScopesList)}", cacheDuration: 60 * 30)]
    protected virtual async Task<List<ClientScopes>> QueryClientScopesList()
    {
        return await clientScopesRepository.GetListAsync();
    }
}